package com.smartleanx.module.hrm.dal.mysql.payrollapproverecord;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.framework.mybatis.core.mapper.BaseMapperX;
import com.smartleanx.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.smartleanx.module.hrm.controller.admin.payrollapproverecord.vo.PayrollApproveRecordPageReqVO;
import com.smartleanx.module.hrm.dal.dataobject.payrollapproverecord.PayrollApproveRecordDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 薪资审批记录 Mapper
 *
 * @author zhangchp
 */
@Mapper
public interface PayrollApproveRecordMapper extends BaseMapperX<PayrollApproveRecordDO> {
    default int updateProcessInstanceId(String processInstanceId, Long id){
        return update(Wrappers.lambdaUpdate(PayrollApproveRecordDO.class)
                .set(PayrollApproveRecordDO::getApproveProcessInstanceId, processInstanceId)
                .eq(PayrollApproveRecordDO::getId, id));
    }

    default int updateApproveResult(Integer approveResult, Long id){
        return update(Wrappers.lambdaUpdate(PayrollApproveRecordDO.class)
                .set(PayrollApproveRecordDO::getApproveResult, approveResult)
                .eq(PayrollApproveRecordDO::getId, id));
    }

    default PageResult<PayrollApproveRecordDO> selectPage(PayrollApproveRecordPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PayrollApproveRecordDO>()
                .eqIfPresent(PayrollApproveRecordDO::getPayrollId, reqVO.getPayrollId())
                .orderByDesc(PayrollApproveRecordDO::getCreateTime));
    }
}